using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;

namespace KbsUmlEditor
{
    class UMLAssociation: UMLObject
    {
        private String richting; //NORTH, EAST, SOUTH, WEST
        private Point eind;
        private Point begin;
        private Point hoek1;
        private Point hoek2;
        private String begineind;

        public UMLAssociation(Point beginPositie, Point eindPositie, String begineind)
            : base(beginPositie,eindPositie)
        {
            this.begineind = begineind;
        }

        public String Richting
        {
            get { return richting; }
            set { richting = value; }
        }

        public void bereken()
        {   
            //Bepaal richting
            switch(begineind)
            {
                case "begin":
                    if (BeginPositie.X == EindPositie.X)
                    {
                        richting = "NORTH";
                    }
                    else 
                    {
                        richting = "WEST";
                    }
                break;
                case "eind":
                    if (BeginPositie.X == EindPositie.X)
                    {
                        richting = "SOUTH";
                    }
                    else
                    {
                        richting = "EAST";
                    }
                break;
            }
           
            //Bereken de hoekpunten adhv de richting en 
            //Begin- en Eindpositie van de lijn
            switch (richting)
            {
                case "NORTH":
                    begin.X = BeginPositie.X;
                    begin.Y = BeginPositie.Y;
                    eind.X = BeginPositie.X;
                    eind.Y = BeginPositie.Y + 1;
                    hoek1.X = eind.X - 1;
                    hoek1.Y = eind.Y;
                    hoek2.X = eind.X + 1;
                    hoek2.Y = eind.Y;
                    break;

                case "SOUTH":
                    begin.X = EindPositie.X;
                    begin.Y = EindPositie.Y;
                    eind.X = EindPositie.X;
                    eind.Y = EindPositie.Y - 1;
                    hoek1.X = eind.X - 1;
                    hoek1.Y = eind.Y;
                    hoek2.X = eind.X + 1;
                    hoek2.Y = eind.Y;
                    break;

                case "EAST":
                    begin.X = EindPositie.X;
                    begin.Y = EindPositie.Y;
                    eind.X = EindPositie.X - 1;
                    eind.Y = EindPositie.Y;
                    hoek1.X = eind.X;
                    hoek1.Y = eind.Y + 1;
                    hoek2.X = eind.X;
                    hoek2.Y = eind.Y - 1;
                    break;

                case "WEST":
                    begin.X = BeginPositie.X;
                    begin.Y = BeginPositie.Y;
                    eind.X = BeginPositie.X + 1;
                    eind.Y = BeginPositie.Y;
                    hoek1.X = eind.X;
                    hoek1.Y = eind.Y + 1;
                    hoek2.X = eind.X;
                    hoek2.Y = eind.Y - 1;
                    break;
            }
        }
	
        public override void Teken(Graphics g, double factor, int grid)
        {
            //grid meeberekenen
            factor = factor * grid;
            
            //Bereken de hoekpunten
            bereken();

            //Definieer de pen
            System.Drawing.Pen myPen;
            myPen = new System.Drawing.Pen(System.Drawing.Color.Black);

            //Definieer het graphics object
            System.Drawing.Graphics formGraphics = g;

            //Teken de eerste lijn
            Point bPos = new Point((int)(begin.X * factor), (int)(begin.Y * factor));
            Point ePos = new Point((int)(eind.X * factor), (int)(eind.Y * factor));
            formGraphics.DrawLine(myPen, bPos, ePos);

            //Teken de tweede lijn
            bPos = new Point((int)(begin.X * factor), (int)(begin.Y * factor));
            ePos = new Point((int)(hoek1.X * factor), (int)(hoek1.Y * factor));
            formGraphics.DrawLine(myPen, bPos, ePos);

            //Teken de derde lijn
            bPos = new Point((int)(begin.X * factor), (int)(begin.Y * factor));
            ePos = new Point((int)(hoek2.X * factor), (int)(hoek2.Y * factor));
            formGraphics.DrawLine(myPen, bPos, ePos);
        }
    }
}
